package com.aaa.member.service.impl;

import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.member.dao.IntegrationHistoryDao;
import com.aaa.member.entity.IntegrationHistory;
import com.aaa.member.service.IntegrationHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (IntegrationHistory)表服务实现类
 *
 * @author LiangLei
 * @since 2020-11-19 14:46:57
 */
@Service("integrationHistoryService")
public class IntegrationHistoryServiceImpl implements IntegrationHistoryService {
    @Resource
    private IntegrationHistoryDao integrationHistoryDao;

    /**
     *  分页加各种条件查询
     */
    @Override
    public Result queryPageByParam(Integer pageNo, Integer pageSize, IntegrationHistory integrationHistory) {
        if(pageNo==null||pageSize==null){
            throw new CustomException(ExceptionConstant.INVALID_ARGUMENT.getErrorCode(),
                    ExceptionConstant.INVALID_ARGUMENT.getErrorMessage());
        }
        //分页
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<IntegrationHistory> pageInfo = new PageInfo<IntegrationHistory>(integrationHistoryDao.queryAll(integrationHistory));
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),pageInfo);
    }

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     * @param id 主键
     */
    @Override
    public IntegrationHistory queryById(Integer id) {
        return this.integrationHistoryDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<IntegrationHistory> queryAllByLimit(int offset, int limit) {
        return this.integrationHistoryDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @Override
    public IntegrationHistory insert(IntegrationHistory integrationHistory) {
        integrationHistory.setCreateTime(new Date());
        this.integrationHistoryDao.insert(integrationHistory);
        return integrationHistory;
    }

    /**
     * 修改数据
     *
     * @param integrationHistory 实例对象
     * @return 实例对象
     */
    @Override
    public IntegrationHistory update(IntegrationHistory integrationHistory) {
        integrationHistory.setCreateTime(new Date());
        this.integrationHistoryDao.update(integrationHistory);
        return this.queryById(integrationHistory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.integrationHistoryDao.deleteById(id) > 0;
    }
}